//
//  T3FPOIManager.swift
//  t3_map
//
//  Created by Cunhai Li on 2024/12/12.
//

import Foundation
import Flutter

class T3FPOIManager {

    /// 根据坐标点，逆地理
    static func regeo(arguments: Any?, result: @escaping FlutterResult) {
        /// arguments示例：
        /// ```
        /// {
        ///    "mapType": 2
        ///    "longitude": 11.111
        ///    "latitude": 11.111
        /// }
        /// ```
        do {
            let json = try T3FJsonUtil.toJson(arguments)
            let mapType: T3FMapType
            if let value = json["mapType"] as? Int {
                mapType = T3FMapType(rawValue: value) ?? .amap
            }
            else {
                mapType = .amap
            }

            switch mapType {
            case .amap:
                T3FMAPOIManager().regeo(arguments: arguments, result: result)
            case .tencentMap:
                T3FTNPOIManager().regeo(arguments: arguments, result: result)
            }
        } catch (let error) {
            let response = ["error": error.localizedDescription]
            let value = try? T3FJsonUtil.toString(response)
            result(value)
        }
    }
}
